package com.qlk.odcinterface.manager.impl;

import java.util.List;

import com.qlk.common.manager.BaseManager;
import com.qlk.common.utils.page.PageUtil;
import com.qlk.odcinterface.domain.PmsFullCutChannel;
import com.qlk.odcinterface.domain.query.PmsFullCutChannelQuery;
import com.qlk.odcinterface.dao.PmsFullCutChannelDao;
import com.qlk.odcinterface.manager.PmsFullCutChannelManager;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * PmsFullCutChannelManager接口的实现类
 * 
 * @author zhaoyanan
 * @version 2016-4-14 13:22:58
 * 
 */
@Component
public class PmsFullCutChannelManagerImpl extends BaseManager implements PmsFullCutChannelManager {
	
    @Autowired
    private PmsFullCutChannelDao pmsFullCutChannelDao;

    /**
     * {@inheritDoc}
     */
    public boolean insert(final List<PmsFullCutChannel> pmsFullCutChannelList) {
        boolean resultFlag = false;
        if (null != pmsFullCutChannelList && pmsFullCutChannelList.size() > 0) {
            for (PmsFullCutChannel pmsFullCutChannel : pmsFullCutChannelList) {
                resultFlag = pmsFullCutChannelDao.insert(pmsFullCutChannel);
                if (!resultFlag) {
                    throw new RuntimeException("批量新增表信息异常");
                }
            }
        }

        return resultFlag;
    }

    /**
     * {@inheritDoc}
     */
    public boolean insert(PmsFullCutChannel pmsFullCutChannel) {
        return pmsFullCutChannelDao.insert(pmsFullCutChannel);
    }

    /**
     * {@inheritDoc}
     */
    public boolean update(final PmsFullCutChannel pmsFullCutChannel) {
        return pmsFullCutChannelDao.update(pmsFullCutChannel);
    }

    /**
     * {@inheritDoc}
     */
    public List<PmsFullCutChannel> queryPmsFullCutChannelList(PmsFullCutChannelQuery queryBean) {
        return pmsFullCutChannelDao.queryPmsFullCutChannelList(queryBean);
    }

    /**
     * {@inheritDoc}
     */
    public List<PmsFullCutChannel> queryPmsFullCutChannelListWithPage(PmsFullCutChannelQuery queryBean,
            PageUtil pageUtil) {
        if (null == queryBean) {
            queryBean = new PmsFullCutChannelQuery();
        }

        // 查询总数
        int totalItem = queryPmsFullCutChannelCount(queryBean);

        if (pageUtil == null) {
            pageUtil = new PageUtil();
        }
        pageUtil.setTotalRow(totalItem);
        pageUtil.init();
        
        if (totalItem > 0) {
            queryBean.setPageIndex(pageUtil.getCurPage());
            queryBean.setPageSize(pageUtil.getPageSize());
            // 调用Dao翻页方法
            return pmsFullCutChannelDao.queryPmsFullCutChannelListWithPage(queryBean);
        }
        return null;
    }

    /**
     * {@inheritDoc}
     */
    public int queryPmsFullCutChannelCount(PmsFullCutChannelQuery queryBean) {
        return pmsFullCutChannelDao.queryPmsFullCutChannelCount(queryBean);
    }

    /**
     * {@inheritDoc}
     */
    public boolean delete(PmsFullCutChannel pmsFullCutChannel) {
        return pmsFullCutChannelDao.delete(pmsFullCutChannel);
    }

    /**
     * {@inheritDoc}
     */
    public PmsFullCutChannel getPmsFullCutChannelById(Integer id) {
        return pmsFullCutChannelDao.getPmsFullCutChannelById(id);
    }

    /**
     * {@inheritDoc}
     */
    public boolean delete(final PmsFullCutChannel[] pmsFullCutChannels) {
        boolean resultFlag = false;
        if (null != pmsFullCutChannels && pmsFullCutChannels.length > 0) {
            for (int i = 0; i < pmsFullCutChannels.length; i++) {
                resultFlag = delete(pmsFullCutChannels[i]);
                if (!resultFlag) {
                    throw new RuntimeException("批量删除表信息异常!");
                }
            }
        }

        return resultFlag;
    }

    /**
     * {@inheritDoc}
     */
    public boolean exist(PmsFullCutChannel pmsFullCutChannel) {
        return pmsFullCutChannelDao.exist(pmsFullCutChannel);
    }
}
